#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "employee.h" 
#define MAX_EMPLOYEES 100



// 从文件中读取员工信息
int readEmployeesFromFile(Employee employees[], int *employeeCount) {
    FILE *file = fopen("employees.txt", "r");
    if (file == NULL) {
        *employeeCount = 0;
        return 1;
    }

    *employeeCount = 0;
    while (*employeeCount < MAX_EMPLOYEES && fscanf(file, "%s %s %s %s %s %s %s %s %s %s %s %s ",
        employees[*employeeCount].info.name, employees[*employeeCount].info.sex,
        employees[*employeeCount].info.birthdate, employees[*employeeCount].info.workday,
        employees[*employeeCount].info.department, employees[*employeeCount].info.category,
        employees[*employeeCount].info.rating, employees[*employeeCount].info.techTitle,
        employees[*employeeCount].info.education, employees[*employeeCount].info.nation,
        employees[*employeeCount].info.nativeplace, employees[*employeeCount].info.address) == 12) {
        fscanf(file, "%f %f %f %f %f %f %f %f %f %f %f %f ",
            &employees[*employeeCount].salary.basicSalary, &employees[*employeeCount].salary.postAllowance,
            &employees[*employeeCount].salary.priceAllowance, &employees[*employeeCount].salary.positionAllowance,
            &employees[*employeeCount].salary.housingAllowance, &employees[*employeeCount].salary.rent,
            &employees[*employeeCount].salary.overtimePay, &employees[*employeeCount].salary.nightShiftPay,
            &employees[*employeeCount].salary.sickLeaveDeduction, &employees[*employeeCount].salary.personalLeaveDeduction,
            &employees[*employeeCount].salary.absenceDeduction, &employees[*employeeCount].salary.otherDeduction);
        fscanf(file, "%f %d %d %d %d %d %d %d %d %f\n",
            &employees[*employeeCount].salary.actualSalary, &employees[*employeeCount].attendance.attendanceDays,
            &employees[*employeeCount].attendance.injuryDays, &employees[*employeeCount].attendance.maternityDays,
            &employees[*employeeCount].attendance.sickLeaveDays, &employees[*employeeCount].attendance.absenceDays,
            &employees[*employeeCount].attendance.personalLeaveDays, &employees[*employeeCount].attendance.overtimeDays,
            &employees[*employeeCount].attendance.nightShiftDays, &employees[*employeeCount].attendance.sickLeaveCoefficient);
        (*employeeCount)++;
    }

    fclose(file);
    return 1;
}


// 将员工信息保存到文件
void SaveEmployeesToFile(Employee employees[], int employeeCount) {
    FILE *file = fopen("employees.txt", "w"); // 使用 "w" 模式覆盖原文件内容
    if (file == NULL) {
        printf("无法打开文件！\n");
        return;
    }
    int i;
    for (i = 0; i < employeeCount; i++) {
        Employee emp = employees[i];
        fprintf(file, "%s %s %s %s %s %s %s %s %s %s %s %s ",
                emp.info.name, emp.info.sex, emp.info.birthdate, emp.info.workday,
                emp.info.department, emp.info.category, emp.info.rating, emp.info.techTitle,
                emp.info.education, emp.info.nation, emp.info.nativeplace, emp.info.address);
        fprintf(file, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f ",
                emp.salary.basicSalary, emp.salary.postAllowance, emp.salary.priceAllowance,
                emp.salary.positionAllowance, emp.salary.housingAllowance, emp.salary.rent,
                emp.salary.overtimePay, emp.salary.nightShiftPay, emp.salary.sickLeaveDeduction,
                emp.salary.personalLeaveDeduction, emp.salary.absenceDeduction, emp.salary.otherDeduction);
        fprintf(file, "%.2f %d %d %d %d %d %d %d %d %.2f\n",
                emp.salary.actualSalary, emp.attendance.attendanceDays, emp.attendance.injuryDays,
                emp.attendance.maternityDays, emp.attendance.sickLeaveDays, emp.attendance.absenceDays,
                emp.attendance.personalLeaveDays, emp.attendance.overtimeDays, emp.attendance.nightShiftDays,
                emp.attendance.sickLeaveCoefficient);
    }

    fclose(file);
}



//打印所有员工信息
void printfallemployee(Employee employees[], int employeeCount){
	int i;
	for(i = 0; i < employeeCount ; i++){
	printf("姓名: %s\n", employees[i].info.name);
            printf("性别；%s\n",employees[i].info.sex) ;
            printf("出生日期；%s\n",employees[i].info.birthdate) ;
            printf("工作日期；%s\n",employees[i].info.workday) ;
            printf("所属部门；%s\n",employees[i].info.department) ;
            printf("人员类别；%s\n",employees[i].info.category) ;
            printf("技术等级；%s\n",employees[i].info.rating) ;
            printf("技术职称；%s\n",employees[i].info.techTitle) ;
            printf("文化程度；%s\n",employees[i].info.education) ;
            printf("民族；%s\n",employees[i].info.nation) ;
            printf("籍贯；%s\n",employees[i].info.nativeplace) ;
            printf("现住址；%s\n",employees[i].info.address) ;
            printf("基本工资；%f\n",employees[i].salary.basicSalary) ;
            printf("岗位津贴；%f\n",employees[i].salary.postAllowance) ;
            printf("物价津贴；%f\n",employees[i].salary.priceAllowance) ;
            printf("职务津贴；%f\n",employees[i].salary.positionAllowance) ;
            printf("住房津贴；%f\n",employees[i].salary.housingAllowance) ;
            printf("房租；%f\n",employees[i].salary.rent) ;
            printf("加班费；%f\n",employees[i].salary.overtimePay) ;
            printf("夜班费；%f\n",employees[i].salary.nightShiftPay) ;
            printf("病假扣款；%f\n",employees[i].salary.sickLeaveDeduction) ;
            printf("事假扣款；%f\n",employees[i].salary.personalLeaveDeduction) ;
            printf("旷工扣款；%f\n",employees[i].salary.absenceDeduction) ;
            printf("其他扣款；%f\n",employees[i].salary.otherDeduction) ;
            printf("实发工资；%f\n",employees[i].salary.actualSalary) ;
            printf("出勤天数；%d\n",employees[i].attendance.attendanceDays) ;
            printf("工伤天数；%d\n",employees[i].attendance.injuryDays) ;
            printf("产假天数；%d\n",employees[i].attendance.maternityDays) ;
            printf("病假天数；%d\n",employees[i].attendance.sickLeaveDays) ;
            printf("旷工天数；%d\n",employees[i].attendance.absenceDays) ;
            printf("事假天数；%d\n",employees[i].attendance.personalLeaveDays) ;
            printf("加班天数；%d\n",employees[i].attendance.overtimeDays) ;
            printf("夜班天数；%d\n",employees[i].attendance.nightShiftDays) ;
			printf("病假系数；%f\n",employees[i].attendance.sickLeaveCoefficient) ; 
			printf("-------------------------\n");
	}
}


	// 插入员工数据
int insertEmployee(Employee employees[], int employeeCount) {
    if (employeeCount >= MAX_EMPLOYEES) {
    	if (!readEmployeesFromFile(employees, &employeeCount)) {
            printf("读取员工文件失败，无法确认是否达到上限。\n");
            return employeeCount;
        }
        if (employeeCount >= MAX_EMPLOYEES) {
            printf("员工数量已达到上限，无法插入新员工。\n");
            return employeeCount;
        }
    }
    Employee newEmployee;
     printf("输入员工姓名；");
     scanf("%s",newEmployee.info.name);

      printf("请输入员工性别；");
      scanf("%s",newEmployee.info.sex);

       printf("请输入员工出生日期；");
       scanf("%s",newEmployee.info.birthdate);

        printf("请输入员工工作日期；");
        scanf("%s",newEmployee.info.workday);

         printf("请输入员工所属部门；");
         scanf("%s",newEmployee.info.department);

          printf("请输入员工人员类别；");
          scanf("%s",newEmployee.info.category);

           printf("请输入员工技术等级；");
           scanf("%s",newEmployee.info.rating);
      
            printf("请输入员工技术职称；");
            scanf("%s",newEmployee.info.techTitle);
   
            printf("请输入员工文化程度；");
            scanf("%s",newEmployee.info.education);
 
            printf("请输入员工民族；");
            scanf("%s",newEmployee.info.nation);

            printf("请输入员工籍贯；");
            scanf("%s",newEmployee.info.nativeplace);

            printf("请输入员工现住址；");
            scanf("%s",newEmployee.info.address);

            
              
          
    // 输入基本工资
    while (1) {
        printf("请输入员工基本工资：");
        scanf("%f", &newEmployee.salary.basicSalary);
        if (newEmployee.salary.basicSalary < 0) {
            printf("无效数据请重新输入\n");
        } else {
           break;
        }
    }

    // 输入岗位津贴
    while (1) {
        printf("请输入员工岗位津贴：");
        scanf("%f", &newEmployee.salary.postAllowance);
        if (newEmployee.salary.postAllowance < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入物价津贴
    while (1) {
        printf("请输入员工物价津贴：");
        scanf("%f", &newEmployee.salary.priceAllowance);
        if (newEmployee.salary.priceAllowance < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入职务津贴
    while (1) {
        printf("请输入员工职务津贴：");
        scanf("%f", &newEmployee.salary.positionAllowance);
        if (newEmployee.salary.positionAllowance < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入住房津贴
    while (1) {
        printf("请输入员工住房津贴：");
        scanf("%f", &newEmployee.salary.housingAllowance);
        if (newEmployee.salary.housingAllowance < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入房租
    while (1) {
        printf("请输入员工房租：");
        scanf("%f", &newEmployee.salary.rent);
        if (newEmployee.salary.rent < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }



    // 输入其他扣款
    while (1) {
        printf("请输入员工其他扣款：");
        scanf("%f", &newEmployee.salary.otherDeduction);
        if (newEmployee.salary.otherDeduction < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入出勤天数
    while (1) {
        printf("请输入员工出勤天数：");
        scanf("%d", &newEmployee.attendance.attendanceDays);
        if (newEmployee.attendance.attendanceDays < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入公伤天数
    while (1) {
        printf("请输入员工公伤天数：");
        scanf("%d", &newEmployee.attendance.injuryDays);
        if (newEmployee.attendance.injuryDays < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入产假天数
    while (1) {
        printf("请输入员工产假天数：");
        scanf("%d", &newEmployee.attendance.maternityDays);
        if (newEmployee.attendance.maternityDays < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入病假天数
    while (1) {
        printf("请输入员工病假天数：");
        scanf("%d", &newEmployee.attendance.sickLeaveDays);
        if (newEmployee.attendance.sickLeaveDays < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入旷工天数
    while (1) {
        printf("请输入员工旷工天数：");
        scanf("%d", &newEmployee.attendance.absenceDays);
        if (newEmployee.attendance.absenceDays < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入事假天数
    while (1) {
        printf("请输入员工事假天数：");
        scanf("%d", &newEmployee.attendance.personalLeaveDays);
        if (newEmployee.attendance.personalLeaveDays < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入加班天数
    while (1) {
        printf("请输入员工加班天数：");
        scanf("%d", &newEmployee.attendance.overtimeDays);
        if (newEmployee.attendance.overtimeDays < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }

    // 输入夜班天数
    while (1) {
        printf("请输入员工夜班天数：");
        scanf("%d", &newEmployee.attendance.nightShiftDays);
        if (newEmployee.attendance.nightShiftDays < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }
    
    // 输入病假系数
    while (1) {
        printf("请输入员工病假系数：");
        scanf("%f", &newEmployee.attendance.sickLeaveCoefficient);
        if (newEmployee.attendance.sickLeaveCoefficient < 0) {
            printf("无效数据请重新输入\n");
        } else {
            break;
        }
    }
        newEmployee.salary.absenceDeduction = 100 * newEmployee.attendance.absenceDays;//旷工扣款 
        
		newEmployee.salary.personalLeaveDeduction = 100 * newEmployee.attendance.personalLeaveDays;//事假扣款
		
		newEmployee.salary.sickLeaveDeduction = 50 * newEmployee.attendance.sickLeaveDays;//病假扣款
		
		newEmployee.salary.overtimePay = 50 * newEmployee.attendance.overtimeDays;//加班费
		
		newEmployee.salary.nightShiftPay = 100 * newEmployee.attendance.nightShiftDays;//夜班费 
		
		newEmployee.salary.actualSalary = newEmployee.salary.basicSalary + newEmployee.salary.postAllowance + 
		newEmployee.salary.priceAllowance + newEmployee.salary.positionAllowance + 
		newEmployee.salary.housingAllowance + newEmployee.salary.overtimePay + newEmployee.salary.nightShiftPay - 
		newEmployee.salary.sickLeaveDeduction - newEmployee.salary.personalLeaveDeduction - 
		newEmployee.salary.absenceDeduction - newEmployee.salary.otherDeduction;//实发工资	

             employees[employeeCount++] = newEmployee;
			  printf("员工数据插入成功。\n");
			  // 保存员工信息到文件
    SaveEmployeesToFile(employees, employeeCount);
    return employeeCount; 
	}
			  
	
		
		// 修改员工数据
void modifyEmployee(Employee employees[],int *employeeCount) {
	 // 先从文件读取数据，保证内存数据是最新的
    if (!readEmployeesFromFile(employees, employeeCount)) {
        return;
    }
	char a[50],b[50],c[50],d[50],e[50],f[50],g[50],h[50],p[50],j[50],k[50],l[50];
	float m,n,o,q,r,x,z,u,v,w,ab,ac,ad;
    char name[50];
    printf("请输入要修改的员工姓名: ");
    scanf("%s", name);
    int i,choice,ba,bc,bd,bf,bg,bh,bj,bk,bl;
    for (i = 0; i < *employeeCount; i++) {
        if (strcmp(employees[i].info.name, name) == 0) {
        	do{	
            printf("请输入需要修改的部分:\n ");
            printf("1.员工姓名\n"); 
            printf("2.员工性别\n"); 
            printf("3.员工出生日期\n"); 
            printf("4.员工参加工作日期\n"); 
            printf("5.所属部门\n"); 
            printf("6.人员类别\n"); 
            printf("7.技术等级\n"); 
            printf("8.技术职称\n"); 
            printf("9.文化程度\n"); 
            printf("10.民族\n"); 
            printf("11.籍贯\n"); 
            printf("12.现住址\n"); 
            printf("13.基本工资\n"); 
            printf("14.岗位津贴\n"); 
            printf("15.物价补贴\n"); 
            printf("16.职务津贴\n"); 
            printf("17.住房补贴\n"); 
            printf("18.房租\n"); 
            printf("19.出勤天数\n"); 
            printf("20.公伤日数\n"); 
            printf("21.产假日数\n"); 
            printf("22.病假日数\n"); 
            printf("23.事假日数\n"); 
            printf("24.其他扣款\n"); 
            printf("25.旷工日数\n"); 
            printf("26.加班日数\n");
			printf("27.夜班日数\n"); 
			printf("28.其他扣款\n"); 
			printf("0.退出\n") ; 
			printf("请输入你的选择：");
			scanf("%d",&choice);
			
			switch(choice){
				
				    case 1:
					printf("请输入员工的新姓名：");
					scanf("%s",a);
					strcpy(employees[i].info.name, a);
					printf("修改成功!\n"); 
					break;
					
					
					case 2:
						printf("请输入员工的新性别；");
						scanf("%s",b);
						 strcpy(employees[i].info.sex, b);
						 	printf("修改成功!\n"); 
					break;
					
					
					case 3:
						printf("请输入员工的新出生日期；"); 
						scanf("%s",c);
						strcpy(employees[i].info.birthdate,c);
							printf("修改成功!\n"); 
					break;
					
					
					case 4:
						printf("请输入员工的新参加工作日期；");
						scanf("%s",d);
						strcpy(employees[i].info.workday,d);
							printf("修改成功!\n"); 
					break;
					
					
					case 5:
						printf("请输入员工的新所属部门；");
						scanf("%s",e) ;
						strcpy(employees[i].info.department,e);
							printf("修改成功!\n"); 
					break;
					
					
					case 6:
						printf("请输入员工的新人员类别；"); 
						scanf("%s",f);
						strcpy(employees[i].info.category,f);
							printf("修改成功!\n"); 
					break;
					
					
					case 7:
						printf("请输入员工的新技术等级；");
						scanf("%s",g);
						strcpy(employees[i].info.rating,g);
							printf("修改成功!\n"); 
					break;
					
					
					case 8:
						printf("请输入员工的新技术职称；");
						scanf("%s",h); 
						strcpy(employees[i].info.techTitle,h);
							printf("修改成功!\n"); 
					break;
					
					
					case 9:
						printf("请输入员工的新文化程度；");
						scanf("%s",p);
						strcpy(employees[i].info.education,p);
							printf("修改成功!\n"); 
					break;
					
					
					case 10:
					    printf("请输入员工的新民族；");
					    scanf("%s",j);
					    strcpy(employees[i].info.nation,j);
					    	printf("修改成功!\n"); 
					break;
					
					
					case 11:
						printf("请输入员工的新籍贯；");
						scanf("%s",k);
						strcpy(employees[i].info.nativeplace,k);
							printf("修改成功!\n"); 
					break;
					
					
					case 12:
						printf("请输入员工的新现住址；");
						scanf("%s",l);
						strcpy(employees[i].info.address,l);
							printf("修改成功!\n"); 
					break;
					
					
					case 13:
						printf("请输入员工的新基本工资；");
						scanf("%f",&m);
						employees[i].salary.basicSalary = m;
							printf("修改成功!\n"); 
					break;
					
					
					case 14:
					    printf("请输入员工的新岗位津贴；");
                        scanf("%f", &n);
                        employees[i].salary.postAllowance = n;
                        	printf("修改成功!\n"); 
					break;
					
					
					case 15:
						printf("请输入员工的新物价补贴；");
                        scanf("%f", &o);
                        employees[i].salary.priceAllowance = o;
                        	printf("修改成功!\n"); 
					break;
					
					
					case 16:
						printf("请输入员工的新职务津贴；");
                        scanf("%f", &q);
                        employees[i].salary.positionAllowance = q;
                        	printf("修改成功!\n"); 
					break;
					
					
					case 17:
						printf("请输入员工的新住房津贴；");
						scanf("%f", &r);
                        employees[i].salary.housingAllowance = r;
                        	printf("修改成功!\n"); 
					break;
					
					
					case 18:
						printf("请输入员工的新房租；");
						 scanf("%f", &x);
                        employees[i].salary.rent = x;
                        	printf("修改成功!\n"); 
					break;
					
				    case 24:
						printf("请输入员工的新其他扣款；");
						scanf("%f",&ac);
						employees[i].salary.otherDeduction = ac;
							printf("修改成功!\n"); 
					break;
					
					case 19:
						printf("请输入员工的新出勤天数；");
						scanf("%d",&bl);
						employees[i].attendance.attendanceDays = bl;
							printf("修改成功!\n"); 
					break;
					
					
					case 20:
						printf("请输入员工的新公伤日数；");
						scanf("%d",&ba);
						employees[i].attendance.injuryDays = ba;
							printf("修改成功!\n"); 
					break;
					
					
					case 21:
						printf("请输入员工的新产假天数；");
						scanf("%d",&bc);
						employees[i].attendance.maternityDays = bc;
							printf("修改成功!\n"); 
					break;
					
					
					case 22:
						printf("请输入员工的新病假天数；");
						scanf("%d",&bd);
						employees[i].attendance.sickLeaveDays = bd;
							printf("修改成功!\n");
							employees[i].salary.sickLeaveDeduction = 50 * bd;
							
					break;
					
					
					case 23:
						printf("请输入员工的新事假天数；");
						scanf("%d",&bf);
						employees[i].attendance.personalLeaveDays = bf;
							printf("修改成功!\n");
							employees[i].salary.personalLeaveDeduction = 100 * bf; 
					break;
					
					
					case 25:
						printf("请输入员工的新旷工日数；");
						scanf("%d",&bh);
						employees[i].attendance.absenceDays = bh;
							printf("修改成功!\n"); 
							employees[i].salary.absenceDeduction = 100 * bh;
					break;
					
					
					case 26:
						printf("请输入员工的新加班日数；");
						scanf("%d",&bg);
						employees[i].attendance.overtimeDays = bg;
							printf("修改成功!\n"); 
							employees[i].salary.overtimePay = 50 * bg;
					break;
					
					
					case 27:
						printf("请输入员工的新夜班日数；");
						scanf("%d",&bj);
						employees[i].attendance.nightShiftDays = bj;
							printf("修改成功!\n"); 
							employees[i].salary.nightShiftPay = 100 * bj;
					break;
					
					
					case 0:
						printf("退出\n"); 
					break; 

			}
			}while (choice != 0);
			
		employees[i].salary.actualSalary = 	employees[i].salary.basicSalary + employees[i].salary.postAllowance 
		+ employees[i].salary.priceAllowance + employees[i].salary.positionAllowance 
		+ employees[i].salary.housingAllowance + employees[i].salary.overtimePay 
		+ employees[i].salary.nightShiftPay - employees[i].salary.sickLeaveDeduction 
		- employees[i].salary.personalLeaveDeduction - employees[i].salary.absenceDeduction 
		-  employees[i].salary.otherDeduction;
				
			
				// 保存员工信息到文件
    SaveEmployeesToFile(employees, *employeeCount);
    return;
        }
    }printf("未找到该员工，无法修改。\n");
}




// 删除员工数据
void deleteEmployee(Employee employees[],int *employeeCount) {
    // 先从文件读取数据，保证内存数据是最新的
    if (!readEmployeesFromFile(employees, employeeCount)) {
        return;
    }
    char name[50];
    printf("请输入要删除的员工姓名: ");
    scanf("%s", name);
    int i, j;
    for (i = 0; i < *employeeCount; i++) {
        if (strcmp(employees[i].info.name, name) == 0) {
            for (j = i; j < *employeeCount - 1; j++) {
                employees[j] = employees[j + 1];
            }
            (*employeeCount)--;
            printf("员工数据删除成功。\n");
            // 保存员工信息到文件
            SaveEmployeesToFile(employees, *employeeCount);
            return;
        }
    }
    printf("未找到该员工，无法删除。\n");
}


// 查询员工数据
void queryEmployee(Employee employees[], int *employeeCount) {
	 // 先从文件读取数据，保证内存数据是最新的
   if (!readEmployeesFromFile(employees, employeeCount)) {
        return; // 如果读取文件失败，直接返回
    }
    char name[50];
    printf("请输入要查询的员工姓名: ");
    scanf("%s", name);
    int i,found = 0;
    for (i = 0; i < *employeeCount; i++) {
        if (strcmp(employees[i].info.name, name) == 0) {
            printf("姓名: %s\n", employees[i].info.name);
            printf("性别；%s\n",employees[i].info.sex) ;
            printf("出生日期；%s\n",employees[i].info.birthdate) ;
            printf("工作日期；%s\n",employees[i].info.workday) ;
            printf("所属部门；%s\n",employees[i].info.department) ;
            printf("人员类别；%s\n",employees[i].info.category) ;
            printf("技术等级；%s\n",employees[i].info.rating) ;
            printf("技术职称；%s\n",employees[i].info.techTitle) ;
            printf("文化程度；%s\n",employees[i].info.education) ;
            printf("民族；%s\n",employees[i].info.nation) ;
            printf("籍贯；%s\n",employees[i].info.nativeplace) ;
            printf("现住址；%s\n",employees[i].info.address) ;
            printf("基本工资；%f\n",employees[i].salary.basicSalary) ;
            printf("岗位津贴；%f\n",employees[i].salary.postAllowance) ;
            printf("物价津贴；%f\n",employees[i].salary.priceAllowance) ;
            printf("职务津贴；%f\n",employees[i].salary.positionAllowance) ;
            printf("住房津贴；%f\n",employees[i].salary.housingAllowance) ;
            printf("房租；%f\n",employees[i].salary.rent) ;
            printf("加班费；%f\n",employees[i].salary.overtimePay) ;
            printf("夜班费；%f\n",employees[i].salary.nightShiftPay) ;
            printf("病假扣款；%f\n",employees[i].salary.sickLeaveDeduction) ;
            printf("事假扣款；%f\n",employees[i].salary.personalLeaveDeduction) ;
            printf("旷工扣款；%f\n",employees[i].salary.absenceDeduction) ;
            printf("其他扣款；%f\n",employees[i].salary.otherDeduction) ;
            printf("实发工资；%f\n",employees[i].salary.actualSalary) ;
            printf("出勤天数；%d\n",employees[i].attendance.attendanceDays) ;
            printf("工伤天数；%d\n",employees[i].attendance.injuryDays) ;
            printf("产假天数；%d\n",employees[i].attendance.maternityDays) ;
            printf("病假天数；%d\n",employees[i].attendance.sickLeaveDays) ;
            printf("旷工天数；%d\n",employees[i].attendance.absenceDays) ;
            printf("事假天数；%d\n",employees[i].attendance.personalLeaveDays) ;
            printf("加班天数；%d\n",employees[i].attendance.overtimeDays) ;
            printf("夜班天数；%d\n",employees[i].attendance.nightShiftDays) ;
			printf("病假系数；%f\n",employees[i].attendance.sickLeaveCoefficient) ; 
            found = 0;
            break;
        }
        found = 1;
    }
    if(found == 1){
        printf("未找到该员工，无法查询。\n");
    }
}
            
            
          //统计员工数据
		   void statistics(Employee employees[] , int employeeCount) {
		   	 // 先从文件读取数据，保证内存数据是最新的
    readEmployeesFromFile(employees, &employeeCount);
    printf("当前员工数量: %d\n", employeeCount);
}


 // 计算个人月工资
void calculatePersonalSalary(Employee employees[], int employeeCount) {
	 // 先从文件读取数据，保证内存数据是最新的
    readEmployeesFromFile(employees, &employeeCount);
	int i,found = 0;
	char name[50];
	float fee;
	printf("请输入要查询的员工；");
	scanf("%s",name);
	 for (i = 0; i < employeeCount; i++){
	if(strcmp(employees[i].info.name,name) == 0){
		fee = employees[i].salary.basicSalary + employees[i].salary.postAllowance 
		+employees[i].salary.priceAllowance + employees[i].salary.positionAllowance 
		+ employees[i].salary.housingAllowance + employees[i].salary.overtimePay 
		+ employees[i].salary.nightShiftPay - employees[i].salary.sickLeaveDeduction 
		- employees[i].salary.personalLeaveDeduction - employees[i].salary.absenceDeduction 
		- employees[i].salary.otherDeduction;
		printf("姓名\t\t\t\t工资\n"); 
		printf("%s\t\t\t\t%f\n",employees[i].info.name,fee);
		found = 1;
		break;
	}
  }
  if (found == 0){
  printf("无此员工\n"); 
  } 
}
	
	
	// 修正病假扣款系数
void modifySickLeaveCoefficient(Employee employees[], int *employeeCount) {
	if (!readEmployeesFromFile(employees, employeeCount)) {
        printf("读取员工数据失败，无法修改病假系数。\n");
        return;
    }
    char name[50];
    printf("请输入要修改病假扣款系数的员工姓名: ");
    scanf("%s", name);
    int i;
    for (i = 0; i < *employeeCount; i++) {
        if (strcmp(employees[i].info.name, name) == 0) {
            float newCoefficient;
            printf("请输入新的病假扣款系数: ");
            scanf("%f", &newCoefficient);
            employees[i].attendance.sickLeaveCoefficient = newCoefficient;
                   	// 保存员工信息到文件
    SaveEmployeesToFile(employees, *employeeCount);
            printf("病假扣款系数修改成功。\n");
            return;
        }
    }
       printf("未找到该员工，无法修改。\n"); 
}



// 打印工资单 
void menu(Employee employees[], int employeeCount){
	 // 先从文件读取数据，保证内存数据是最新的
    readEmployeesFromFile(employees, &employeeCount);
	
	int i,choice;
	char bumen[50];
	float fee = 0;
	
	do{
	printf("请选择你要打印的工资单；\n");
	printf("1.工资计算表\n");
	printf("2.个人工资单\n");
	printf("3.部门工资单\n");
	printf("4.工资汇总表\n");
	printf("0.退出\n");
	printf("请输入你的选择；\n");
	 scanf("%d",&choice);
	 switch(choice){
	 	
	 	
	 	case 1://工资计算表 
	 		 printf("工资计算表\n");
    printf("姓名\t基本工资\t岗位津贴\t物价补贴\t职务津贴\t住房补贴\t房租\t加班费\t夜班费\t病假扣款\t事假扣款\t旷工扣款\t其它扣款\t实发工资\n"); 
    for (i = 0; i < employeeCount; i++) {
        printf("%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",
               employees[i].info.name, employees[i].salary.basicSalary, employees[i].salary.postAllowance,
               employees[i].salary.priceAllowance, employees[i].salary.positionAllowance,
               employees[i].salary.housingAllowance, employees[i].salary.rent, employees[i].salary.overtimePay,
               employees[i].salary.nightShiftPay, employees[i].salary.sickLeaveDeduction,
               employees[i].salary.personalLeaveDeduction, employees[i].salary.absenceDeduction,
               employees[i].salary.otherDeduction, employees[i].salary.actualSalary);
    }
break ;
	
	 	case 2://个人工资表 
	 		printf("姓名\t\t\t工资\n");
	 	for (i = 0; i < employeeCount; i++) {
	 		printf("%s\t\t\t%.2f\n",employees[i].info.name,employees[i].salary.actualSalary);
		 }
		 break ;
		 
	 	case 3://部门工资表 
	 		printf("请输入你要查询的部门；\n");
	 		scanf("%s",bumen);
	 		int found = 0;
	 		for (i = 0; i < employeeCount; i++){
	 			if(strcmp(employees[i].info.department,bumen) == 0){
	 				printf("姓名；%s    工资；%.2f\n",employees[i].info.name,employees[i].salary.actualSalary) ;
	 				found = 1;
				 }
				 			 }
			if(found == 0){
			printf("无此部门\n");
			}
				 			  
	 		break ;
	 		
	    case 4://工资汇总表 
	    	for (i = 0; i < employeeCount; i++){
	    		fee = fee + employees[i].salary.actualSalary;
			}
	    	printf("本月工资共发；%.2f元\n",fee);
	    	break ;
	    	
		case 0:	//退出系统 
		printf("退出系统\n");
		break ;
		
		
		default:
printf("无效的选择，请重新输入。\n");
	 	
}
}	while (choice != 0);
}

	
// 主菜单
void showMenu() {
	
	
	Employee employees[MAX_EMPLOYEES];
    int employeeCount = 0;
    readEmployeesFromFile(employees, &employeeCount);
    
    
int choice;
do {
printf("\n某大学教工工资管理系统\n");
printf("1. 插入员工数据\n");
printf("2. 修改员工数据\n");
printf("3. 删除员工数据\n");
printf("4. 查询员工数据\n");
printf("5. 统计员工数据\n");
printf("6. 计算个人月工资\n");
printf("7. 修正病假扣款系数\n");
printf("8. 打印工资计算表、个人工资单、部门工资单、工作汇总表\n");
printf("9. 打印所有员工信息\n"); 
printf("0. 退出\n");
printf("请输入你的选择: ");
scanf("%d", &choice);

switch (choice) {
	
case 1:
employeeCount = insertEmployee(employees, employeeCount);//插入员工数据 。 
break;

case 2:
modifyEmployee(employees, &employeeCount);// 修改员工数据 。 
break;

case 3:
deleteEmployee(employees, &employeeCount);//删除员工数据 。 
break;

case 4:
queryEmployee(employees, &employeeCount);//查询员工数据 。 
break;

case 5:
statistics(employees, &employeeCount);//统计员工数据 。 
break;

case 6: 
calculatePersonalSalary(employees, &employeeCount);//计算个人月工资。 
break;

case 7:
modifySickLeaveCoefficient(employees, &employeeCount);//修正病假扣款系数 。 
break;

case 8:
if (employeeCount <= 0) {
        printf("没有员工信息可供打印。\n");
        return;
    }
    menu(employees, &employeeCount);//打印工资单。
break;

case 9:
printfallemployee(employees, employeeCount);
break;

case 0:
printf("退出系统。\n");//退出 。 
break;

default:
printf("无效的选择，请重新输入。\n");

}
} while (choice != 0);
}